package com.cooba.dialog;

import android.animation.ValueAnimator;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.cooba.R;
import com.cooba.views.choicecity.CityPicker;

/**
 * Created by Administrator on 2016/6/15.
 */
public class ChoiceCityDialog extends Dialog implements
        OnClickListener {
    int layoutRes;// 布局文件
    Context context;
    private TextView btnCancel;
    private DialogListener listener;
    private TextView btnComfirm;
    private CityPicker cityPicker;

    public ChoiceCityDialog(Context context) {
        super(context);
        this.context = context;
    }

    /**
     * 自定义布局的构造方法
     *
     * @param context
     * @param resLayout
     */
    public ChoiceCityDialog(Context context, int resLayout) {
        super(context);
        this.context = context;
        this.layoutRes = resLayout;
    }

    /**
     * 自定义主题及布局的构造方法
     *
     * @param context
     * @param theme
     * @param resLayout
     */
    public ChoiceCityDialog(Context context, int theme, int resLayout,
                            DialogListener listener) {
        super(context, theme);
        this.context = context;
        this.layoutRes = resLayout;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(layoutRes);

        // 根据id在布局中找到控件对象
        btnComfirm = (TextView) findViewById(R.id.comfirm_btn);
        btnCancel = (TextView) findViewById(R.id.cancel_btn);
        cityPicker = (CityPicker) findViewById(R.id.citypicker);
        // 为按钮绑定点击事件监听器
        btnComfirm.setOnClickListener(this);
        btnCancel.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.comfirm_btn:
                listener.getCity(cityPicker.getCity_string());
                this.dismiss();
                break;

            case R.id.cancel_btn:
                this.dismiss();
                break;
        }
    }

    public interface DialogListener {

        void getCity(String city);
    }
}
